package db

import (
	"github.com/jinzhu/gorm"
	uuid "github.com/satori/go.uuid"
	"qweewq.tk/flyff/pgk/common/game"
	"strings"
)

const (
	LEVEL_1 = iota
	LEVEL_2
	LEVEL_3
)

/**
TbBank 银行数据表
每个帐号具有一个银行帐号，不同的角色只是该帐号旗下的使用者.
*/
type TbBank struct {
	gorm.Model
	//Type 帐号类， {LEVEL_1, LEVEL_2, LEVEL_3, ...}
	Type uint8 `gorm:"type:smallint"`
	//Uuid 采用UUID做为银行帐号
	Uid string `gorm:"type:varchar(32);not null;unique;index"`
	//用于备注
	Remark string
	//TbAccountID 帐号ID
	TbAccountID uint
}

type TbActorBank struct {
	gorm.Model
	//common.Gold 角色银行中的金币
	game.Gold
	//Uid 相关联的帐号ID
	Uid          string `gorm:"type:varchar(32);not null;unique;index"`
	BankPassword string `gorm:"type:char(4);default:'0000'"`
	//Items 角色银行中物品列表
	Items []TbItem
	//TbActorID 角色ID
	TbActorID uint
}

func (self *TbBank) BeforeCreate(scope *gorm.Scope) error {
	var uid string
	uid = strings.Replace(uuid.NewV4().String(), "-", "", -1)
	return scope.SetColumn("Uid", uid)
}
